import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class AccessManager {

	public static ClientActions clientLogin(AccountDBManager accountDBManager, CustomerDBManager customerDBManager, PropertyDBManager propertyDBManager, DepositDBManager depositDBManager, DepositTypesDBManager depositTypesDBManager, BalanceDBManager balanceDBManager, Connection conn, ClientReports clientReports, long userId, long password) {

		ClientActions clientActions = null;
		Statement statement = null;
		ResultSet resultSet = null;

		String query = "SELECT * FROM customers WHERE cust_id = " + userId + " AND password=" + password;
		try {
			statement = conn.createStatement();

			resultSet = statement.executeQuery(query);

			if (resultSet.next()) {
				clientActions = new ClientActions(accountDBManager, customerDBManager, propertyDBManager, depositDBManager, depositTypesDBManager, clientReports, balanceDBManager);
				System.out.println("[AccessManager]: Client login successfully.");
			} else {
				System.out.println("[AccessManager]: Client login fail.");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				resultSet.close();
				statement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}

		return clientActions;
	}

	public static AdminActions adminLogin(AccountDBManager accountDBManager, CustomerDBManager customerDBManager, PropertyDBManager propertyDBManager, RankDBManager rankDBManager, GeneralReports generalReports, AdminReports adminReports, DepositTypesDBManager depositTypesDBManager, BalanceDBManager balanceDBManager, DepositDBManager depositDBManager, String password) {

		AdminActions adminActions = null;

		if (propertyDBManager.getPropertyByKey("admin_password").equals(password)) {
			adminActions = new AdminActions(accountDBManager, customerDBManager, propertyDBManager, rankDBManager, generalReports, adminReports, depositTypesDBManager, balanceDBManager, depositDBManager);
			System.out.println("[Mbank]: Admin login successfully.");
		} else {
			System.out.println("[AccessManager]: Admin login fail.");
		}

		return adminActions;
	}

}
